import time

from selenium import webdriver
from selenium.webdriver.common.by import By

# 创建浏览器驱动对象
driver = webdriver.Edge()
# 隐式等待
driver.implicitly_wait(10)  # 单位：秒
# 打开网页
driver.get("http://localhost:5173/login")
# 获取页面标题
print(driver.title)
# 查找元素
username = driver.find_element(By.XPATH, "/html/body/div/div/div/div[2]/form/div[1]/div[2]/div[1]/div/input")
password = driver.find_element(By.XPATH, "/html/body/div/div/div/div[2]/form/div[2]/div[2]/div[1]/div/input")
captcha = driver.find_element(By.XPATH, "/html/body/div/div/div/div[2]/form/div[3]/div[2]/div[1]/div/input")
button = driver.find_element(By.XPATH, "/html/body/div/div/div/div[2]/form/div[4]/div[2]/button")
# 输入账号、密码、验证码
username.send_keys("zlcode123456")
password.send_keys("zlcode123456")
captcha.send_keys("r56x")
# 强制等待，单位：秒
time.sleep(2)
# 点击按钮
button.click()
time.sleep(2)

print(driver.title)
write_button = driver.find_element(By.XPATH, "/html/body/div/div/div[3]/div/div[3]/div[1]/div[1]/div")
print(driver.window_handles)
write_button.click()
time.sleep(2)

print(driver.window_handles)  # 打印所有页面的句柄
driver.switch_to.window(driver.window_handles[1])
print(driver.title)
content = driver.find_element(By.XPATH, "/html/body/div[1]/div/div[4]/div[1]/div/div[3]/div/div[3]/div/div[2]/div/div/div/p")
sendTime = driver.find_element(By.XPATH, "/html/body/div[1]/div/div[4]/div[1]/div/div[3]/div/div[5]/div[1]/div[2]/div/input")
email = driver.find_element(By.XPATH, "/html/body/div[1]/div/div[4]/div[1]/div/div[3]/div/input[2]")
send_button = driver.find_element(By.XPATH, "/html/body/div[1]/div/div[4]/div[1]/div/div[3]/div/div[9]/div[1]/button/span[2]")
content.clear()
content.send_keys("hello")
sendTime.send_keys("2025-04-27 00:00:00")
email.send_keys("2186529582@qq.com")
time.sleep(2)
send_button.click()
greeText = driver.find_element(By.XPATH, "/html/body/div[1]/div/div[4]/div[1]/div/div[2]/div/div/footer/div/button[2]/span")
greeText.click()
time.sleep(2)